﻿// Author: Radu-Mihail
// Project: UsersModule, File: UserFactory.cs
// Namespace: UsersModule, Class: UserFactory
// Path: G:\Secure Project\Library\UsersModule
// Code lines: 32, Size of file: 847 Bytes
// Creation date: 1/13/2009 7:26 PM
// Last modified: 1/13/2009 7:39 PM

#region Using directives
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#endregion

namespace UsersModule
{
    public static class UserFactory
    {

        /// <summary>
        /// Get user
        /// </summary>
        /// <param name="userDetails">User details de forma -> idUtilizator*penalizat*idTipUtilizator*activ*lastName</param>
        /// <returns>Generic user</returns>
        public static GenericUser GetUser(string userDetails, string userName)
        {
            string[] userInfo = userDetails.Split(new char[] { '*' });
            int userType = Convert.ToInt32(userInfo[2]) - 1;
            switch (userType)
            {
                case (int)UserTypes.ADMIN:
                    return null;
                case (int)UserTypes.STUDENT:
                    return new User(userName, UserTypes.STUDENT, Convert.ToInt32(userInfo[1]) == 1, Convert.ToInt32(userInfo[3]) == 1, int.Parse(userInfo[0]));
                case (int)UserTypes.TEACHER:
                    return new User(userName, UserTypes.TEACHER, Convert.ToInt32(userInfo[1]) == 1, Convert.ToInt32(userInfo[3]) == 1, int.Parse(userInfo[0]));
                case (int)UserTypes.EXTERN:
                    return new User(userName, UserTypes.EXTERN, Convert.ToInt32(userInfo[1]) == 1, Convert.ToInt32(userInfo[3]) == 1, int.Parse(userInfo[0]));
                default:
                    return new Publisher(userName, UserTypes.PUBLISHER, userInfo[4], Convert.ToInt32(userInfo[1]) == 1);
                    
            }
                
        } // GetUser(userDetails)
    }
}
